#include "SerialPort.h"
#include <iostream>

int main() {
    SerialPort serial;

    serial.SetTimeoutMs(150);

    if (serial.Open("COM9", 115200)) {
        std::cout << "Serial port opened successfully" << std::endl;

        ev_packet_t packet;
        packet.user = 1;
        packet.seq = 0;
        packet.cmd = 0xFFF8;
        packet.len = 4;
        packet.data[0] = 100;
        packet.data[1] = 0;
        packet.data[2] = 0;
        packet.data[3] = 0;

        if (serial.SendData(&packet)) {
            std::cout << "Packet sent successfully" << std::endl;
        } else {
            std::cerr << "Failed to send packet" << std::endl;
        }

        SerialPort::MessagePtr receivedPacket;
        while (serial.GetMessage(receivedPacket)) {
            std::cout << "Received packet - cmd: " << receivedPacket->cmd
                      << ", len: " << receivedPacket->len
                      << ", seq: " << (int)receivedPacket->seq
                      << ", user: " << (int)receivedPacket->user << std::endl;
        }

        serial.Close();
    } else {
        std::cerr << "Failed to open serial port" << std::endl;
    }

    return 0;
}